package com.cdp.common.utils;

import java.util.*;

public class MapSorter {

    private static final List<String> PRICE_ORDER = Arrays.asList(
            "水", "水泥PⅡ 52.5R", "机制砂", "碎石_5~25mm", "矿渣粉_S95", "粉煤灰_Ⅱ级", "减水剂", "增效剂_HX-T608"
    );

    private static final List<String> VARIABLE_ORDER = Arrays.asList(
            "水", "水泥PⅡ 52.5R", "机制砂", "碎石_5~25mm", "矿渣粉_S95", "粉煤灰_Ⅱ级", "减水剂", "增效剂_HX-T608"
    );

    private static final List<String> CONSTRAINT_ORDER = Arrays.asList(
            "胶凝材料", "水胶比", "水灰比", "砂胶比", "砂率", "单方材料总质量", "28天抗压强度", "坍落度"
    );

    public static LinkedHashMap<String, Double> sortPricesTon(Map<String, Double> pricesTon) {
        return sortMapByOrder(pricesTon, PRICE_ORDER);
    }

    public static LinkedHashMap<String, List<Double>> sortVariableRanges(Map<String, List<Double>> variableRanges) {
        return sortMapByOrder(variableRanges, VARIABLE_ORDER);
    }

    public static LinkedHashMap<String, List<Double>> sortCombinedConstraints(Map<String, List<Double>> combinedConstraints) {
        return sortMapByOrder(combinedConstraints, CONSTRAINT_ORDER);
    }

    private static <T> LinkedHashMap<String, T> sortMapByOrder(Map<String, T> map, List<String> order) {
        LinkedHashMap<String, T> sorted = new LinkedHashMap<>();
        for (String key : order) {
            if (map.containsKey(key)) {
                sorted.put(key, map.get(key));
            }
        }
        return sorted;
    }
}
